<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>计费管理</el-breadcrumb-item>
      <el-breadcrumb-item>费用查询</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row :gutter="25">
        <el-col :span="10">
          <!-- 搜索区域 -->
          <el-input
            placeholder="请输入搜索内容"
            v-model="queryInfo.query"
            clearable
            @clear="getUserList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getUserList"
            ></el-button>
          </el-input>
        </el-col>

        <el-col :span="12">
          <el-link @click="check" style="margin-left: 400px">计费规则<i class="el-icon-view el-icon--right"></i> </el-link>
        </el-col>

      </el-row>
      <el-table :data="userList" border="" stripe="">
        <!-- 索引列 -->
        <el-table-column type="index"></el-table-column>
        <el-table-column label="用户名" prop="name"></el-table-column>
        <el-table-column label="电话" prop="tel"></el-table-column>
        <el-table-column label="密码" prop="passwd"></el-table-column>
        <el-table-column label="角色" prop="role"></el-table-column>
        <el-table-column label="群组数" prop="gcount"></el-table-column>
        <el-table-column label="问卷数" prop="qcount"></el-table-column>
        <el-table-column label="应付金额" prop="money"></el-table-column>
      </el-table>

      <div>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pageNum"
          :page-sizes="[1, 2, 5, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import Vue from "vue";
export default {
  created() {
    this.getUserList();
  },
  data() {
    return {
        queryInfo: {
        query: "", //查询信息
        pageNum: 1, //当前页
        pageSize: 5, //每一页最大数
      },
      userList: [], //用户列表
      total: 0, //租户下的用户总记录数
    };
  },
  methods: {
    //获取所有用户 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>????????????分页没写
    async getUserList() {
      let level = window.sessionStorage.getItem("level");
      let name = window.sessionStorage.getItem("name");

      await this.$http({
        method: "post",
        url: "/allUser",
        data: {
          query: this.queryInfo.query,
          pageNum: this.queryInfo.pageNum,
          pageSize: this.queryInfo.pageSize,
          name: name,
          level: level,
        },
      }).then((response) => {
        let list = response.data.data.list;
        this.userList=[];
        list.forEach((user)=>this.addrole(user));
        this.total = response.data.data.total;
      });

    },
    async addrole(user) {
        user = JSON.parse(JSON.stringify(user));
        let name= user.name;
        let temp,temp2;
        await this.$http({
          method: "post",
          url: "/cntQInTenant?name=" + name,
        }).then((response) => {
          if (response.data.code == "666") {
            temp=response.data.data;
            Vue.set(user, "qcount", response.data.data); 
          } else {
            this.$message.error(response.data.message);
          }
        });

        await this.$http({
          method: "post",
          url: "/cntGInTenant?name=" + name,
        }).then((response) => {
          if (response.data.code == "666") {
            temp2=response.data.data;
            Vue.set(user, "gcount", response.data.data); 
          } else {
            this.$message.error(response.data.message);
          }
        });
        console.log(temp);
        console.log(temp2);
        Vue.set(user, "money", temp2+temp*0.5); 
        if (user.level == "2") {
          Vue.set(user, "role", "租户"); //正确姿势
          this.userList.push(user);
        }
        if (user.level == "3") {
          Vue.set(user, "role", "用户"); //正确姿势
          this.userList.push(user);
        }
        console.log(this.userList);
    },
    //最大数
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getUserList();
    },

    //pageNum触发的动作
    handleCurrentChange(newPage) {
      this.queryInfo.pageNum = newPage;
      this.getUserList();
    },

    handleSizeChange1(newSize) {
      this.aqueryInfo.pageSize = newSize;
      this.getAnswerList();
    },
    check(){
      this.$alert('该租户关联群组每个1元，关联用户的已发布问卷每个0.5元', '计费规则', {
          confirmButtonText: '确定',
        });
    },

    //pageNum触发的动作
    handleCurrentChange1(newPage) {
      this.aqueryInfo.pageNum = newPage;
      this.getAnswerList();
    },
  },
};
</script>

<style lang="less" scoped>
.el-breadcrumb {
  margin-bottom: 15px;
  font-size: 17px;
}
</style>